package game.actions;

import edu.monash.fit2099.engine.actions.Action;
import edu.monash.fit2099.engine.actors.Actor;
import edu.monash.fit2099.engine.positions.GameMap;
import edu.monash.fit2099.engine.positions.Location;
import game.items.Food;

/** 通用“食用”动作：应用效果后移除该物品（从背包或地面）。 */
public class ConsumeAction extends Action {

    private final Food food;

    public ConsumeAction(Food food) {
        this.food = food;
    }

    @Override
    public String execute(Actor actor, GameMap map) {
        String result = food.consumeEffect(actor, map);

        // 从背包移除；若不在背包，则从当前地面移除
        if (actor.getItemInventory().contains(food)) {
            actor.removeItemFromInventory(food);
        } else {
            Location here = map.locationOf(actor);
            if (here != null) {
                here.removeItem(food);
            }
        }
        return result;
    }

    @Override
    public String menuDescription(Actor actor) {
        return "Consume " + food;
    }
}
